<template>
  <div class="header-wrapper">
    <el-row class="header">
      <el-col :span="4">
        <a href="/home" class="logo"></a>
      </el-col>
      <el-col :span="10" :offset="10">
        <el-input
          v-model="keyword"
          placeholder="请输入搜索关键字"
          size="large"
          clearable
          class="search-wrapper"
          @change="change">
          <template #prepend>
            <el-select v-model="type" placeholder="搜索类型" style="width: 110px">
              <el-option label="搜标题" value="title"></el-option>
              <el-option label="搜内容" value="content"></el-option>
            </el-select>
          </template>
          <template #append>
            <el-button :icon="Search"></el-button>
          </template>
        </el-input>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { Search } from '@element-plus/icons-vue'
export default {
  data() {
    return {
      Search,
      keyword: '',
      type: ''
    };
  },
  methods: {
    change(){
      console.log(  this.type , this.keyword );
      let params = { 
        type: this.type ? this.type : 'title',
        keyword: this.keyword ,
        pageSize: this.$parent.$parent.pageSize ,
        currentPage: this.$parent.$parent.currentPage
      }
      this.axios.get( '/topic/search' , { params } )
                .then( resp=>{
                  let { total , topics } = resp.data ;
                  this.$parent.$parent.total = total ;
                  this.$parent.$parent.topics = topics ;
                }).catch( error=>{
                  console.log( error );
                });
    }
  }
};
</script>

<style scoped>
.header-wrapper {
  background: #f90;
}
.header {
  width: 90%;
  height: 100px;
  margin: auto;
}

.header a {
  display: block;
  width: 80px;
  height: 80px;
  margin-top: 10px;
  background: url("../assets/logo.jpg") center no-repeat;
  background-size: contain;
}

.search-wrapper {
  margin-top: 30px ;
}
</style>